package com.qiankan.qmsj.receive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.qiankan.qmsj.event.NetWorkChangeEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Administrator on 2017/3/26.
 */

public class NetworkReceiver extends BroadcastReceiver {
    public static boolean hasNetWork;

    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobileNetInfo = cm.getActiveNetworkInfo();
        if (mobileNetInfo != null) {
            hasNetWork = mobileNetInfo.isConnected();
        } else {
            hasNetWork = false;
        }
        EventBus.getDefault().post(new NetWorkChangeEvent(hasNetWork));
    }
}
